package com.gyul.findmystock.util;

import android.app.Service;
import android.content.SharedPreferences;
import android.util.Log;

public class PreferencesUtils {
	private static String TAG = "PreferencesUtils";
	private static SharedPreferences preferences = null;
	private static SharedPreferences.Editor editor = null;
	
	static public void initialize() {
		preferences = Configs.context.getSharedPreferences("FindMyStockPreferences", Service.MODE_PRIVATE);
		editor = preferences.edit();
		
		editor.commit();
	}
	
	static public boolean checkInitialization() {
		return preferences != null;
	}
	
	static public boolean getBoolean(String key) {
		return preferences.getBoolean(key, false);
	}
	
	static public String getString(String key) {
		return preferences.getString(key, null);
	}
	
	static public int getInt(String key) {
		return preferences.getInt(key, -1);
	}
	
	static public void setBoolean(String key, boolean value) {
		Log.d(TAG, key + " -> " + value );
		editor.putBoolean(key, value);
		editor.commit();
	}
	
	static public void setString(String key, String value) {
		Log.d(TAG, key + " -> " + value );
		editor.putString(key, value);
		editor.commit();
	}
	
	static public void setInt(String key, int value) {
		Log.d(TAG, key + " -> " + value );
		editor.putInt(key, value);
		editor.commit();
	}
}
